Skip to content

Fix Storybook sidebar: generate per-story pages so DocFX active-state works natively#5

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-storybook-integration-issues
Draft

Fix Storybook sidebar: generate per-story pages so DocFX active-state works natively#5
Copilot wants to merge 2 commits intomainfrom
copilot/fix-storybook-integration-issues

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

DocFX ignores query string parameters when computing TOC active state. All story sidebar items shared storybook.html as their base URL (differentiated only by ?story=), causing DocFX to mark every story as active simultaneously.

Approach

Replace the single-page + query-param model with individual HTML pages per story. Each story now gets a unique URL (stories/{storyId}.html), so DocFX's native active-state, breadcrumb, and highlighting all work correctly without any JS workarounds.

Changes

preprocess-storybooks.ts

  • New generateStoryFiles(): creates stub .md files under stories/ for each story in the Storybook index, with front matter embedding the story's path and ID. Writes a .gitignore to prevent accidental commits of generated files
  • buildTocFromStorybook(): TOC hrefs changed from storybook.md?story={id}stories/{id}.md
  • updateTocWithStorybook(): also updates the root Storybook TOC entry to point to the first story page
  • processMarkdownFile(): calls generateStoryFiles() and skips already-generated story pages (guard against recursion)

postprocess-storybooks.ts

  • injectStorybookIframe(storyId?): story-specific pages get a simplified iframe with the story URL hardcoded — the fixTocActiveState, fixBreadcrumb, and "first story redirect" JS hacks are removed entirely
  • Main storybook page retains backward-compatible ?story= URL param handling for existing links
  • StorybookConfig interface: added story?: string

Generated stub example

# stories/timemachine-timemachine--default.md (generated)
---
title: TimeMachine/TimeMachine - Default
storybook:
  path: /Source/JavaScript/Components
  story: timemachine-timemachine--default
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…in the sidebar

DocFX was treating all story TOC items as the same page because they all pointed
to storybook.html with different ?story= query params, which DocFX ignores for
active-state matching.

Fix: during pre-processing, generate a stub .md file for each story in a
stories/ subdirectory. DocFX builds these into unique HTML pages so each story
has its own URL. DocFX's native active-state detection then works correctly —
only the current story is highlighted in the sidebar.

Post-processing now injects a simplified iframe (no JS workarounds needed) for
story-specific pages, and retains backward-compatible ?story= URL handling on
the main storybook page.

Co-authored-by: einari <134365+einari@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Storybook integration in DocFX navigation sidebar Fix Storybook sidebar: generate per-story pages so DocFX active-state works natively Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants